import { GameObject } from './GameObject';

export abstract class Component {
    public gameObject: GameObject;
    public active: boolean = true;
    
    constructor(gameObject: GameObject) {
        this.gameObject = gameObject;
    }
    
    /**
     * Called when the component is attached to a GameObject
     */
    public onAttach(): void {}
    
    /**
     * Called when the component is detached from a GameObject
     */
    public onDetach(): void {}
    
    /**
     * Called every frame to update component logic
     * @param deltaTime Time in seconds since last update
     */
    public update(deltaTime: number): void {}
    
    /**
     * Called every frame to render the component
     * @param ctx Canvas rendering context
     */
    public render(ctx: CanvasRenderingContext2D): void {}
    
    /**
     * Called when the component is destroyed
     * Override this method to clean up resources
     */
    public destroy(): void {
        this.onDetach();
    }
    
    /**
     * Get a component from the parent GameObject
     */
    protected getComponent<T extends Component>(componentType: new (...args: any[]) => T): T | null {
        return this.gameObject.getComponent(componentType);
    }
} 